<script type="text/javascript">
function get_selected_process_id() {
	var dropdown = document.getElementsByName('edit_process')[0];
	return dropdown.options[dropdown.selectedIndex].value;
}
</script>

	<fieldset>
		<legend>Running processes</legend>

<?php if (isset($participating_processes)): ?>
		
		<fieldset>
			<legend>You participate in</legend>
			
			<dl>
<?php foreach ($participating_processes as $process): ?>

				<dt><?php echo $process['process_name'] ?> (Started on <?php echo $process['start_date'] ?>)</dt>
<?php foreach ($process['stages'] as $stage): ?>
					<dd><?php echo $stage['stage_name'] ?> (Started on <?php echo $stage['start_date'] ?>)
					<?php if ($stage['participates'] == TRUE): ?>
					<input type="button" value="Participate!" onclick="document.location='<?php echo site_url('home/participate/' . $stage['stage_instance_id']); ?>'" />
					<?php else: ?>
					<input type="button" value="You don't participate in this stage" disabled="disabled" />
					<?php endif; ?></dd>
<?php endforeach; ?>
<?php endforeach; ?>
			</dl>
		</fieldset>
<?php endif; ?>

<?php if (isset($started_by_user)): ?>		
		<fieldset>
			<legend>Started by you</legend>
			<dl>
<?php foreach ($started_by_user as $p): ?>
			<dt><?php echo $p['process_name'] ?> (Started on <?php echo $p['start_date'] ?>)</dt>
<?php foreach ($p['stages'] as $s): ?>
				<dd><?php echo $s['stage_name'] ?> (Started on <?php echo $s['start_date'] ?>)</dd>
<?php endforeach; ?>
			
<?php endforeach; ?>
			</dl>
		</fieldset>
	</fieldset>
<?php endif; ?>

<?php if (($user_level == PROCESS_MANAGER) || ($user_level == USER_MANAGER) || ($user_level == ADMIN)): ?>
	<fieldset>
		<legend>Administrator options</legend>
		<form>
<?php if (($user_level == PROCESS_MANAGER) || ($user_level == ADMIN)): ?>
			<input type="button" value="Design new process" onclick="javascript:document.location = '<?php echo site_url('processdesigner/create_process'); ?>'" />
<?php endif; ?>
<?php if (($user_level == USER_MANAGER) || ($user_level == ADMIN)): ?>
			<input type="button" value="Add new user" onclick="javascript:document.location = '<?php echo site_url('users/add_user'); ?>'" />
<?php endif; ?>
		</form>
	</fieldset>
<?php endif; ?>

<?php if (($user_level == PROCESS_MANAGER) || ($user_level == ADMIN)): ?>
	<fieldset>
		<legend>Process owner actions</legend>
		
		<fieldset>
			<legend>Start existing processes</legend>
			<?php echo form_open('home/start_process'); ?>
			<?php echo form_dropdown('process', $processes); ?>
			<?php echo form_submit('submit', 'Start'); ?>
			<?php echo form_close(); ?>
		</fieldset>
		
		<fieldset>
			<legend>Edit an existing process</legend>
			<form>
			<?php echo form_dropdown('edit_process', $processes); ?>
			<input type="button" value="Edit" onclick="javascript:document.location = '<?php echo site_url('processdesigner/view_process') ?>/' + get_selected_process_id()" />
			</form>
		</fieldset>
	</fieldset>
<?php endif; ?>